<template>
  <a-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-row class="form-row" :gutter="24">
          <a-col :md="12" :sm="8">
            <a-form-item label="生产订单号" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="[ 'productOrdNo', validatorRules.productOrdNo]" placeholder="请输入生产订单号"></a-input>
            </a-form-item>
          </a-col>

          <a-col :md="12" :sm="8">
            <a-form-item label="装置编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="[ 'unitNo', validatorRules.unitNo]" placeholder="请输入装置编号"></a-input>
            </a-form-item>
          </a-col>
        </a-row>



        <a-form-item label="硬件型号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'yjxh', validatorRules.yjxh]" placeholder="请输入硬件型号"></a-input>
        </a-form-item>
        <a-form-item label="软件版本" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'softVersion', validatorRules.softVersion]" placeholder="请输入软件版本"></a-input>
        </a-form-item>
        <a-form-item label="采样电压幅值" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'samVoltageAmp', validatorRules.samVoltageAmp]" placeholder="请输入采样电压幅值"></a-input>
        </a-form-item>
        <a-form-item label="采样电压相位" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'samVoltagePhsae', validatorRules.samVoltagePhsae]" placeholder="请输入采样电压相位"></a-input>
        </a-form-item>
        <a-form-item label="采样电流幅值" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'samCurrenAmp', validatorRules.samCurrenAmp]" placeholder="请输入采样电流幅值"></a-input>
        </a-form-item>
        <a-form-item label="采样电流相位" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'samCurrenPhase', validatorRules.samCurrenPhase]" placeholder="请输入采样电流相位"></a-input>
        </a-form-item>
        <a-form-item label="开入回路" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'openInCircuit', validatorRules.openInCircuit]" placeholder="请输入开入回路"></a-input>
        </a-form-item>
        <a-form-item label="开出回路" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'openOutCircuit', validatorRules.openOutCircuit]" placeholder="请输入开出回路"></a-input>
        </a-form-item>
        <a-form-item label="功能测试" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'functionTest', validatorRules.functionTest]" placeholder="请输入功能测试"></a-input>
        </a-form-item>
        <a-form-item label="工序类型" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'processType', validatorRules.processType]" placeholder="请输入工序类型"></a-input>
        </a-form-item>
        <a-form-item label="工艺编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'processRouteNo', validatorRules.processRouteNo]" placeholder="请输入工艺编码"></a-input>
        </a-form-item>
        <a-form-item label="remark1" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'remark1', validatorRules.remark1]" placeholder="请输入remark1"></a-input>
        </a-form-item>
        <a-form-item label="remark2" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'remark2', validatorRules.remark2]" placeholder="请输入remark2"></a-input>
        </a-form-item>
        <a-form-item label="remark3" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'remark3', validatorRules.remark3]" placeholder="请输入remark3"></a-input>
        </a-form-item>
        <a-form-item label="remark4" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'remark4', validatorRules.remark4]" placeholder="请输入remark4"></a-input>
        </a-form-item>
        <a-form-item label="remark5" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'remark5', validatorRules.remark5]" placeholder="请输入remark5"></a-input>
        </a-form-item>
        <a-form-item label="1：未读0：成功；" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'ioflag', validatorRules.ioflag]" placeholder="请输入1：未读0：成功；"></a-input>
        </a-form-item>
        <a-form-item label="结束时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择结束时间" v-decorator="[ 'endTime', validatorRules.endTime]" :trigger-change="true" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="tid" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="[ 'tid', validatorRules.tid]" placeholder="请输入tid" style="width: 100%"/>
        </a-form-item>
        
      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import JDate from '@/components/jeecg/JDate'  
  
  export default {
    name: "ZxjEip2cZzjcModal",
    components: { 
      JDate,
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title:"操作",
        width:800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        validatorRules:{
        productOrdNo:{rules: [{ required: true, message: '请输入生产订单号!' }]},
        unitNo:{rules: [{ required: true, message: '请输入装置编号!' }]},
        yjxh:{rules: [{ required: true, message: '请输入硬件型号!' }]},
        softVersion:{rules: [{ required: true, message: '请输入软件版本!' }]},
        samVoltageAmp:{rules: [{ required: true, message: '请输入采样电压幅值!' }]},
        samVoltagePhsae:{rules: [{ required: true, message: '请输入采样电压相位!' }]},
        samCurrenAmp:{rules: [{ required: true, message: '请输入采样电流幅值!' }]},
        samCurrenPhase:{rules: [{ required: true, message: '请输入采样电流相位!' }]},
        openInCircuit:{rules: [{ required: true, message: '请输入开入回路!' }]},
        openOutCircuit:{rules: [{ required: true, message: '请输入开出回路!' }]},
        functionTest:{rules: [{ required: true, message: '请输入功能测试!' }]},
        processType:{rules: [{ required: true, message: '请输入工序类型!' }]},
        processRouteNo:{},
        remark1:{},
        remark2:{},
        remark3:{},
        remark4:{},
        remark5:{},
        ioflag:{rules: [{ required: true, message: '请输入1：未读0：成功；!' }]},
        endTime:{},
        tid:{rules: [{ required: true, message: '请输入tid!' }]},
        },
        url: {
          add: "/twice/zxjEip2cZzjc/add",
          edit: "/twice/zxjEip2cZzjc/edit",
        }
     
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'productOrdNo','unitNo','yjxh','softVersion','samVoltageAmp','samVoltagePhsae','samCurrenAmp','samCurrenPhase','openInCircuit','openOutCircuit','functionTest','processType','processRouteNo','remark1','remark2','remark3','remark4','remark5','ioflag','endTime','tid'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            console.log("表单提交数据",formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }
         
        })
      },
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'productOrdNo','unitNo','yjxh','softVersion','samVoltageAmp','samVoltagePhsae','samCurrenAmp','samCurrenPhase','openInCircuit','openOutCircuit','functionTest','processType','processRouteNo','remark1','remark2','remark3','remark4','remark5','ioflag','endTime','tid'))
      }
      
    }
  }
</script>